home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / klsucnvt / convertt.frm (.txt) next >
Encoding:
Visual Basic Form  |  1997-12-03  |  11.2 KB  |  327 lines

  1. VERSION 5.00
  2. Begin VB.Form frmUnitConversion 
  3.    Caption         =   "Conversion Utility"
  4.    ClientHeight    =   4635
  5.    ClientLeft      =   2325
  6.    ClientTop       =   2145
  7.    ClientWidth     =   4980
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   4635
  10.    ScaleWidth      =   4980
  11.    Begin VB.OptionButton Option1 
  12.       Caption         =   "Pressure"
  13.       Height          =   465
  14.       Index           =   8
  15.       Left            =   3675
  16.       TabIndex        =   19
  17.       Top             =   75
  18.       Width           =   915
  19.    End
  20.    Begin VB.OptionButton Option1 
  21.       Caption         =   "Volume"
  22.       Height          =   465
  23.       Index           =   7
  24.       Left            =   3765
  25.       TabIndex        =   18
  26.       Top             =   525
  27.       Width           =   840
  28.    End
  29.    Begin VB.OptionButton Option1 
  30.       Caption         =   "Energy"
  31.       Height          =   465
  32.       Index           =   6
  33.       Left            =   2775
  34.       TabIndex        =   17
  35.       Top             =   525
  36.       Width           =   840
  37.    End
  38.    Begin VB.OptionButton Option1 
  39.       Caption         =   "Mass"
  40.       Height          =   465
  41.       Index           =   5
  42.       Left            =   1875
  43.       TabIndex        =   16
  44.       Top             =   525
  45.       Width           =   765
  46.    End
  47.    Begin VB.TextBox txtReturnVal 
  48.       Height          =   315
  49.       Left            =   1110
  50.       TabIndex        =   14
  51.       Top             =   4050
  52.       Width           =   2565
  53.    End
  54.    Begin VB.OptionButton Option1 
  55.       Caption         =   "Angle"
  56.       Height          =   465
  57.       Index           =   4
  58.       Left            =   990
  59.       TabIndex        =   4
  60.       Top             =   525
  61.       Width           =   765
  62.    End
  63.    Begin VB.OptionButton Option1 
  64.       Caption         =   "Time"
  65.       Height          =   465
  66.       Index           =   3
  67.       Left            =   165
  68.       TabIndex        =   3
  69.       Top             =   525
  70.       Width           =   765
  71.    End
  72.    Begin VB.OptionButton Option1 
  73.       Caption         =   "Speed"
  74.       Height          =   465
  75.       Index           =   2
  76.       Left            =   2685
  77.       TabIndex        =   2
  78.       Top             =   75
  79.       Width           =   840
  80.    End
  81.    Begin VB.OptionButton Option1 
  82.       Caption         =   "Temperature"
  83.       Height          =   465
  84.       Index           =   1
  85.       Left            =   1335
  86.       TabIndex        =   1
  87.       Top             =   75
  88.       Width           =   1215
  89.    End
  90.    Begin VB.OptionButton Option1 
  91.       Caption         =   "Distance"
  92.       Height          =   465
  93.       Index           =   0
  94.       Left            =   210
  95.       TabIndex        =   0
  96.       Top             =   75
  97.       Width           =   990
  98.    End
  99.    Begin VB.CommandButton cmdConvert 
  100.       Caption         =   "Calculate"
  101.       Default         =   -1  'True
  102.       Height          =   465
  103.       Left            =   1200
  104.       TabIndex        =   12
  105.       TabStop         =   0   'False
  106.       Top             =   3075
  107.       Width           =   1215
  108.    End
  109.    Begin VB.CommandButton cmdDoneConversions 
  110.       Caption         =   "Close"
  111.       Height          =   465
  112.       Left            =   2415
  113.       TabIndex        =   9
  114.       TabStop         =   0   'False
  115.       Top             =   3075
  116.       Width           =   1215
  117.    End
  118.    Begin VB.Frame fraConversion 
  119.       Height          =   1890
  120.       Left            =   75
  121.       TabIndex        =   8
  122.       Top             =   975
  123.       Width           =   4815
  124.       Begin VB.TextBox txtValueIn 
  125.          Height          =   315
  126.          Left            =   1035
  127.          TabIndex        =   7
  128.          Top             =   1425
  129.          Width           =   2565
  130.       End
  131.       Begin VB.ComboBox cmbUnitsTo 
  132.          Height          =   315
  133.          Left            =   2475
  134.          Sorted          =   -1  'True
  135.          TabIndex        =   6
  136.          Top             =   600
  137.          Width           =   2190
  138.       End
  139.       Begin VB.ComboBox cmbUnitsFrom 
  140.          Height          =   315
  141.          Left            =   165
  142.          Sorted          =   -1  'True
  143.          TabIndex        =   5
  144.          Top             =   600
  145.          Width           =   2190
  146.       End
  147.       Begin VB.Label Label1 
  148.          AutoSize        =   -1  'True
  149.          Caption         =   "Value to Convert"
  150.          Height          =   195
  151.          Index           =   2
  152.          Left            =   1725
  153.          TabIndex        =   13
  154.          Top             =   1125
  155.          Width           =   1185
  156.       End
  157.       Begin VB.Label Label1 
  158.          AutoSize        =   -1  'True
  159.          Caption         =   "Units to Convert TO"
  160.          Height          =   195
  161.          Index           =   1
  162.          Left            =   2925
  163.          TabIndex        =   11
  164.          Top             =   300
  165.          Width           =   1410
  166.       End
  167.       Begin VB.Label Label1 
  168.          AutoSize        =   -1  'True
  169.          Caption         =   "Units to Convert FROM"
  170.          Height          =   195
  171.          Index           =   0
  172.          Left            =   435
  173.          TabIndex        =   10
  174.          Top             =   300
  175.          Width           =   1650
  176.       End
  177.    End
  178.    Begin VB.Label Label1 
  179.       AutoSize        =   -1  'True
  180.       Caption         =   "Return Value"
  181.       Height          =   195
  182.       Index           =   3
  183.       Left            =   1920
  184.       TabIndex        =   15
  185.       Top             =   3750
  186.       Width           =   930
  187.    End
  188. Attribute VB_Name = "frmUnitConversion"
  189. Attribute VB_GlobalNameSpace = False
  190. Attribute VB_Creatable = False
  191. Attribute VB_PredeclaredId = True
  192. Attribute VB_Exposed = False
  193. Option Explicit
  194. Private Const typeDISTANCE = 0
  195. Private Const typeTEMPERATURE = 1
  196. Private Const typeSPEED = 2
  197. Private Const typeTIME = 3
  198. Private Const typeANGLE = 4
  199. Private Const typeMASS = 5
  200. Private Const typeENERGY = 6
  201. Private Const typeVOLUME = 7
  202. Private Const typePRESSURE = 8
  203. Private ConvertDLL As New UnitConverter
  204. Private Sub cmdConvert_Click()
  205. Dim i As Integer, iConvertThis As Integer
  206. On Error GoTo ErrorHandler
  207. 'make sure a number is filled into the text field
  208.     If Not IsNumeric(txtValueIn.Text) Then
  209.         MsgBox "Non-numeric value for input.  No conversion done.", vbExclamation, "Conversion Utility"
  210.         txtReturnVal.Text = ""
  211.         Exit Sub
  212.     End If
  213. 'determine which type of conversion they are doing
  214.     For i = 0 To (Option1.Count - 1)
  215.         If Option1(i).Value Then
  216.             iConvertThis = i
  217.             Exit For
  218.         End If
  219.     Next
  220. 'run the conversion DLL
  221.     Dim dblReturnVal As Double
  222.     Dim strIn As String, strOut As String
  223.     'determine the units they want for in/out
  224.     i = InStr(cmbUnitsFrom.Text, "-")
  225.     strIn = UCase(Trim(Left(cmbUnitsFrom.Text, i - 1)))
  226.     i = InStr(cmbUnitsTo.Text, "-")
  227.     strOut = UCase(Trim(Left(cmbUnitsTo.Text, i - 1)))
  228.     Select Case Option1(iConvertThis).Caption
  229.         Case "Distance"
  230.             dblReturnVal = ConvertDLL.Length(strIn, Val(txtValueIn.Text), strOut)
  231.         Case "Temperature"
  232.             dblReturnVal = ConvertDLL.Temperature(strIn, Val(txtValueIn.Text), strOut)
  233.         Case "Speed"
  234.             dblReturnVal = ConvertDLL.Speed(strIn, Val(txtValueIn.Text), strOut)
  235.         Case "Time"
  236.             dblReturnVal = ConvertDLL.Time(strIn, Val(txtValueIn.Text), strOut)
  237.         Case "Angle"
  238.             dblReturnVal = ConvertDLL.Angle(strIn, Val(txtValueIn.Text), strOut)
  239.         Case "Mass"
  240.             dblReturnVal = ConvertDLL.Mass(strIn, Val(txtValueIn.Text), strOut)
  241.         Case "Energy"
  242.             dblReturnVal = ConvertDLL.Energy(strIn, Val(txtValueIn.Text), strOut)
  243.         Case "Pressure"
  244.             dblReturnVal = ConvertDLL.Pressure(strIn, Val(txtValueIn.Text), strOut)
  245.         Case "Volume"
  246.             dblReturnVal = ConvertDLL.Volume(strIn, Val(txtValueIn.Text), strOut)
  247.     End Select
  248. txtReturnVal.Text = CStr(dblReturnVal)
  249. Exit Sub
  250. ErrorHandler:
  251.     MsgBox Err.Description, , Err.Number
  252. End Sub
  253. Private Sub cmdDoneConversions_Click()
  254. Unload Me
  255. End Sub
  256. Private Sub Option1_Click(Index As Integer)
  257. 'set up the combo box lists
  258.     cmbUnitsFrom.Clear
  259.     cmbUnitsTo.Clear
  260.     Select Case Index
  261.         Case typeDISTANCE
  262.             cmbUnitsFrom.AddItem "KM - Kilometers"
  263.             cmbUnitsFrom.AddItem "NM - Nautical Miles"
  264.             cmbUnitsFrom.AddItem "FT - Feet"
  265.             cmbUnitsFrom.AddItem "KF - Kilofeet"
  266.             cmbUnitsFrom.AddItem "HM - Hectometers"
  267.             cmbUnitsFrom.AddItem "YD - Yards"
  268.             cmbUnitsFrom.AddItem "M - Meters"
  269.             cmbUnitsFrom.AddItem "SM - Statute Miles"
  270.             cmbUnitsFrom.AddItem "IN - Inches"
  271.             cmbUnitsFrom.AddItem "CM - Centimeters"
  272.         Case typeTEMPERATURE
  273.             cmbUnitsFrom.AddItem "F - Fahrenheit"
  274.             cmbUnitsFrom.AddItem "C - Celsius"
  275.             cmbUnitsFrom.AddItem "K - Kelvin"
  276.         Case typeSPEED
  277.             cmbUnitsFrom.AddItem "MPS - Meters per Second"
  278.             cmbUnitsFrom.AddItem "KPH - Kilometers per Hour"
  279.             cmbUnitsFrom.AddItem "KTS - Knots"
  280.             cmbUnitsFrom.AddItem "MPH - Miles per Hour"
  281.         Case typeTIME
  282.             cmbUnitsFrom.AddItem "DAY - Days"
  283.             cmbUnitsFrom.AddItem "HR - Hours"
  284.             cmbUnitsFrom.AddItem "MIN - Minutes"
  285.             cmbUnitsFrom.AddItem "SEC - Seconds"
  286.             cmbUnitsFrom.AddItem "WK - Weeks"
  287.             cmbUnitsFrom.AddItem "MON - Months"
  288.         Case typeANGLE
  289.             cmbUnitsFrom.AddItem "MIL - Mil"
  290.             cmbUnitsFrom.AddItem "DEG - Degree"
  291.             cmbUnitsFrom.AddItem "RAD - Radian"
  292.         Case typeMASS
  293.             cmbUnitsFrom.AddItem "KG - Kilogram"
  294.             cmbUnitsFrom.AddItem "LB - Pound"
  295.             cmbUnitsFrom.AddItem "TON - Ton"
  296.             cmbUnitsFrom.AddItem "MT - Metric Ton"
  297.             cmbUnitsFrom.AddItem "OZ - Ounce"
  298.             cmbUnitsFrom.AddItem "G - Grams"
  299.         Case typeENERGY
  300.             cmbUnitsFrom.AddItem "J - Joule"
  301.             cmbUnitsFrom.AddItem "CAL - Calorie"
  302.             cmbUnitsFrom.AddItem "BTU - British Thermal Unit"
  303.             cmbUnitsFrom.AddItem "ERG - Erg (CGS unit)"
  304.             cmbUnitsFrom.AddItem "FTLB - Foot-Pounds"
  305.             cmbUnitsFrom.AddItem "KCAL - Kilocalorie"
  306.             cmbUnitsFrom.AddItem "KWH - Kilowatt Hour"
  307.             cmbUnitsFrom.AddItem "EV - Electron Volt"
  308.         Case typePRESSURE
  309.             cmbUnitsFrom.AddItem "PA - Pascal"
  310.             cmbUnitsFrom.AddItem "ATM - Atmospheres"
  311.             cmbUnitsFrom.AddItem "TORR - Milimeters of Mercury"
  312.             cmbUnitsFrom.AddItem "BAR - Bars"
  313.             cmbUnitsFrom.AddItem "PSI - Pounds per Square Inch"
  314.             cmbUnitsFrom.AddItem "KPA - Kilopascal"
  315.         Case typeVOLUME
  316.             cmbUnitsFrom.AddItem "LT - Liter"
  317.             cmbUnitsFrom.AddItem "GA - Gallon"
  318.             cmbUnitsFrom.AddItem "QT - Quart"
  319.             cmbUnitsFrom.AddItem "PT - Pint"
  320.             cmbUnitsFrom.AddItem "OZ - Fluid Ounce"
  321.     End Select
  322. Dim i As Integer
  323. For i = 1 To cmbUnitsFrom.ListCount
  324.     cmbUnitsTo.AddItem cmbUnitsFrom.List(i - 1)
  325. Next i
  326. End Sub
  327.